<?php

namespace App\Http\Form\KfCashRegister;


use App\Enums\WorkOrder\OrderEnum;
use App\Http\Form\Form;
use App\Http\Form\FormAttribute;
use App\Http\Form\FormInterface;
use App\Http\Form\FormValidate;
use App\Models\WorkOrder\WorkOrderApplyContentModel;
use App\Models\WorkOrder\WorkOrderApplyMainModel;
use App\Support\CustomForm\Attribute\AttributeMapSupport;
use App\Support\CustomForm\Attribute\AttributeSupport;
use App\Support\CustomForm\AttributeWorkOrderSupport;
use App\Support\CustomForm\Validate\ValidateSupport;
use App\Support\Facade\CustomerValidator;
use Illuminate\Support\Collection;
use Illuminate\Validation\Validator;

/**
 * @property KfCashRegisterFormAttribute shopCode
 * @property KfCashRegisterFormAttribute shopName
 * @property KfCashRegisterFormAttribute address
 * @property KfCashRegisterFormAttribute detailAddress
 * @property KfCashRegisterFormAttribute mobile
 * @property KfCashRegisterFormAttribute shopCharge
 * @property KfCashRegisterFormAttribute authorizationLetterImg
 * @property KfCashRegisterFormAttribute businessTime
 * @property KfCashRegisterFormAttribute cashierSystem
 *
 * @property KfCashRegisterFormAttribute collectionType
 *
 * @property KfCashRegisterFormAttribute accountOpenPermitImg
 * @property KfCashRegisterFormAttribute bankReceiptImg
 * @property KfCashRegisterFormAttribute businessLicenseImg
 * @property KfCashRegisterFormAttribute enterpriseName
 * @property KfCashRegisterFormAttribute businessLicenseNumber
 * @property KfCashRegisterFormAttribute businessPremises
 * @property KfCashRegisterFormAttribute legalPersonIdentityCardFront
 * @property KfCashRegisterFormAttribute legalPersonIdentityCardBack
 * @property KfCashRegisterFormAttribute legalPersonIdentityCardValidityPeriod
 * @property KfCashRegisterFormAttribute legalPersonIdentityCardWithFront
 * @property KfCashRegisterFormAttribute legalPersonIdentityCardWithBack
 * @property KfCashRegisterFormAttribute legalPersonUsername
 * @property KfCashRegisterFormAttribute legalPersonIdentityCardNumber
 *
 * @property KfCashRegisterFormAttribute collectionPersonIdentityCardFront
 * @property KfCashRegisterFormAttribute collectionPersonIdentityCardBack
 * @property KfCashRegisterFormAttribute collectionPersonIdentityCardValidityPeriod
 * @property KfCashRegisterFormAttribute collectionPersonIdentityCardWithFront
 * @property KfCashRegisterFormAttribute collectionPersonIdentityCardWithBack
 * @property KfCashRegisterFormAttribute collectionPersonUsername
 * @property KfCashRegisterFormAttribute collectionPersonIdentityCardNumber
 * @property KfCashRegisterFormAttribute collectionEqBankCard
 * @property KfCashRegisterFormAttribute relationshipProofImg
 * @property KfCashRegisterFormAttribute bankCardImgFront
 * @property KfCashRegisterFormAttribute bankCardImgBack
 *
 * @property KfCashRegisterFormAttribute accountBank
 * @property KfCashRegisterFormAttribute provinceBank
 * @property KfCashRegisterFormAttribute accountBranchBank
 * @property KfCashRegisterFormAttribute collectionBankAccount
 * @property KfCashRegisterFormAttribute bankReserveMobile
 *
 * @property KfCashRegisterFormAttribute takeDeliveryAddress
 * @property KfCashRegisterFormAttribute takeDeliveryDetailAddress
 * @property KfCashRegisterFormAttribute takeDeliveryUserName
 * @property KfCashRegisterFormAttribute takeDeliveryUserMobile
 *
 * @property KfCashRegisterFormAttribute expectOpenTime
 */
class KfCashRegisterForm extends Form implements FormInterface
{

    /**
     * 门店信息表单
     */
    public function shopInfoForm(Collection $formContent)
    {
        KfCashRegisterFormAttribute::getInstance(
            "shopCode",
            AttributeSupport::INPUT_TYPE_STRING,
            "门店编号"
        )->setValidateRules(
            KfCashRegisterFormValidate::getInstance()->setRequired(true)
                                      ->setDataType(ValidateSupport::DATA_TYPE_STRING)
                                      ->setContentLength(0, 6)
        )->setCustomAttribute(
            ["disabled", true],
            ["placeholder", "请填写门店编号"]
        )->setValue(
            $formContent, ""
        )->setBeforeBuildHandle(
            function (AttributeSupport $attributeSupport) use ($formContent) {
                if (!$formContent->get("shopCode")) {
                    $attributeSupport->setCustomAttribute(["disabled", false]);
                }
            }
        );

        KfCashRegisterFormAttribute::getInstance(
            "shopName",
            AttributeSupport::INPUT_TYPE_STRING,
            "门店名称"
        )->setValidateRules(
            KfCashRegisterFormValidate::getInstance()->setRequired(true)
                                      ->setDataType(ValidateSupport::DATA_TYPE_STRING)
                                      ->setContentLength(0, 36)
        )->setCustomAttribute(
            ["placeholder", "请填写门店名称"]
        )->setValue($formContent, "");;

        KfCashRegisterFormAttribute::getInstance(
            "address",
            AttributeSupport::INPUT_TYPE_ADDRESS,
            "门店省市区"
        )->setValidateRules(
            KfCashRegisterFormValidate::addressValidate()
        )->setCustomAttribute(
            ["placeholder", "请选择所在省市区"]
        )->setValue($formContent, []);

        KfCashRegisterFormAttribute::getInstance(
            "detailAddress",
            AttributeSupport::INPUT_TYPE_STRING,
            "详细地址"
        )->setValidateRules(
            KfCashRegisterFormValidate::getInstance()->setRequired(true)
                                      ->setDataType(ValidateSupport::DATA_TYPE_STRING)
                                      ->setContentLength(0, 120)
        )->setCustomAttribute(
            ["placeholder", "请填写详细地址"]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "businessTime",
            AttributeSupport::INPUT_DATE_TIME_RANGE,
            "营业时间"
        )->setValidateRules(
            KfCashRegisterFormValidate::dateRangeValidate(FormValidate::DATE_VALIDATE_FORMAT_5, false)
        )->setPlaceholder(
            "请选择营业时间"
        )->setDateFormat(
            AttributeSupport::DATE_FORMAT_5
        )->setValue($formContent, ["startTime" => "10:00", "endTime" => "22:00"]);

        KfCashRegisterFormAttribute::getInstance(
            "mobile",
            AttributeSupport::INPUT_TYPE_STRING,
            "门店手机"
        )->setValidateRules(
            KfCashRegisterFormValidate::mobileValidate()
        )->setCustomAttribute(
            ["placeholder", "用作夸父收银管理账号"]
        )->setValue($formContent, "");;

        KfCashRegisterFormAttribute::getInstance(
            "shopCharge",
            AttributeSupport::INPUT_TYPE_STRING,
            "门店负责人"
        )->setValidateRules(
            KfCashRegisterFormValidate::getInstance()->setRequired(true)
                                      ->setDataType(ValidateSupport::DATA_TYPE_STRING)
                                      ->setContentLength(0, 6)
        )->setPlaceholder(
            "请填写门店负责人"
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "authorizationLetterImg",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "夸父品牌授权书",
            true
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::getInstance()->setRequired(false)
                                      ->setDataType(ValidateSupport::DATA_TYPE_ARRAY)
                                      ->setContentLength(1, 1)
        )->registerHandleSaveValueFunc(
            FormAttribute::getImgGroupSaveFunc()
        )->setExampleImages(
            ["https://file.51kuafu.com/1a/c3/330483dee327bc7410a36906b6fe7d88be2a76458646fbb060b8dde5cb40.png"]
        )->setRemark(
            '授权书下载地址：夸父商家-我的-开店订单-合同资料-运营资料-开店授权书'
        )->setValue(
            $formContent, ""
        )->setBeforeBuildHandle(function (AttributeSupport $attributeSupport) use ($formContent) {
            if ($formContent->get("initAuthorizationLetterImg", false)) {
                $attributeSupport->setCustomAttribute(["disabled", true]);
            }
        });

        KfCashRegisterFormAttribute::getInstance(
            "cashierSystem",
            AttributeSupport::INPUT_TYPE_SELECT,
            "门店收银系统"
        )->setValidateRules(
            KfCashRegisterFormValidate::inIntValidate(WorkOrderApplyContentModel::CASHIER_SYSTEM_MAP, true)
        )->setOptions(
            WorkOrderApplyContentModel::CASHIER_SYSTEM_MAP
        )->setValue($formContent);
    }

    /**
     * 收款人表单信息
     */
    public function collectionInformationForm(Collection $formContent)
    {
        KfCashRegisterFormAttribute::getInstance(
            "collectionType",
            AttributeSupport::INPUT_TYPE_SELECT,
            "收款类型"
        )->setValidateRules(
            KfCashRegisterFormValidate::getInstance()->setRequired(true)
                                      ->setDataType(ValidateSupport::DATA_TYPE_INT)
                                      ->setIn(array_keys(WorkOrderApplyContentModel::COLLECTION_TYPE_MAP))
        )->setOptions(
            WorkOrderApplyContentModel::COLLECTION_TYPE_MAP
        )->setValue($formContent, "");


        KfCashRegisterFormAttribute::getInstance(
            "accountOpenPermitImg",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "开户许可证（盖公章）",
            true
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()
                                      ->setExcludeEq(
                                          [[$this->collectionType->getInputName()=>
                                          WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
                                      )
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]
        )->setExampleImages(
            ["https://file.51kuafu.com/39/b7/e2835b41e6b90e799c812de9b2bcf1ec942ad11f43dd87d40d3a6d0c247b.png"]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "bankReceiptImg",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "对公账户银行回执单截图",
            true
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()
                                      ->setExcludeEq(
                                          [[$this->collectionType->getInputName()=>
                                          WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
                                      )
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]
        )->setExampleImages(
            ["https://img.51kuafu.com/1/0/6c2c3c82965fed85aef3e6abd831995d.jpeg"]
        )->setValue($formContent, "");


        KfCashRegisterFormAttribute::getInstance(
            "collectionPersonIdentityCardFront",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "收款人身份证人像面",
            true
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]]
            )
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]
        )->setExampleImages(
            ["https://file.51kuafu.com/64/a4/613f464330f89f1fe43b35ba667b023178af84b4c7ef4574ed0e01c867a5.png"]
        )->setValue($formContent, []);

        KfCashRegisterFormAttribute::getInstance(
            "collectionPersonIdentityCardBack",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "收款人身份证国徽面",
            true
        )->registerHandleSaveValueFunc(
            FormAttribute::getImgGroupSaveFunc()
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]]
            )
        )->setExampleImages(
            ["https://file.51kuafu.com/49/49/784be96a9a10a712d946f3f184b263e074aeb9cea3ed6c7b125f4ed2dd9b.png"]
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "collectionPersonIdentityCardValidityPeriod",
            AttributeSupport::INPUT_TYPE_STRING,
            "收款人身份证有效期"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 36, false)
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]
        )->setValue($formContent, "");


        KfCashRegisterFormAttribute::getInstance(
            "collectionPersonIdentityCardWithFront",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "收款人手持身份证人像面",
            true
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]]
            )
        )->setCustomAttribute(
            ["descList", WorkOrderApplyContentModel::DEFAULT_PERSON_IDENTITY_CARD_DESC_LIST]
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]
        )->setExampleImages(
            [WorkOrderApplyContentModel::DEFAULT_PERSON_IDENTITY_CARD_HAND_IMG]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "collectionPersonIdentityCardWithBack",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "收款人手持身份证国徽面",
            true
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]]
            )
        )->setCustomAttribute(
            ["descList", WorkOrderApplyContentModel::DEFAULT_PERSON_IDENTITY_CARD_DESC_LIST]
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]
        )->setExampleImages(
            [WorkOrderApplyContentModel::DEFAULT_PERSON_IDENTITY_CARD_HAND_BACK_IMG]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "collectionPersonUsername",
            AttributeSupport::INPUT_TYPE_STRING,
            "收款人姓名"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 12)
                                      ->setExcludeEq(
                                          [[$this->collectionType->getInputName()=>
                                          WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]]
                                      )
        )->setPlaceholder(
            "请填写收款人姓名"
        )->setRelations(
            [
                $this->collectionType->getInputName(),
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE
            ]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "collectionPersonIdentityCardNumber",
            AttributeSupport::INPUT_TYPE_STRING,
            "收款人身份证号"
        )->setValidateRules(
            KfCashRegisterFormValidate::identityCardValidate()
                                      ->setExcludeEq(
                                          [[$this->collectionType->getInputName()=>
                                          WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]]
                                      )
        )->setPlaceholder(
            "请填写收款人身份证号"
        )->setRelations(
            [
                $this->collectionType->getInputName(),
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE
            ]
        )->setValue($formContent, "");


//        KfCashRegisterFormAttribute::getInstance(
//            "collectionEqBankCard",
//            AttributeSupport::INPUT_TYPE_SELECT,
//            "商户法人和收款人是否一致"
//        )->setValidateRules(
//            KfCashRegisterFormValidate::getInstance()
//                                      ->setDataType(ValidateSupport::DATA_TYPE_INT)
//                                      ->setIn(array_keys(WorkOrderApplyContentModel::COLLECTION_EQ_BANK_CARD_MAP))
//                                      ->setExcludeEq($this->collectionType->getInputName(),
//                                          WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE)
//        )->setOptions(
//            WorkOrderApplyContentModel::COLLECTION_EQ_BANK_CARD_MAP
//        )->setRelations(
//            [
//                $this->collectionType->getInputName(),
//                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE
//            ]
//        )->setPlaceholder(
//            "请选择"
//        )->setValue($formContent, "");

//        KfCashRegisterFormAttribute::getInstance(
//            "relationshipProofImg",
//            AttributeSupport::INPUT_TYPE_IMG_GROUP,
//            "关系证明（1张）",
//            true
//        )->setValidateRules(
//            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
//                $this->collectionEqBankCard->getInputName(),
//                WorkOrderApplyContentModel::COLLECTION_EQ_BANK_CARD_NO
//            )
//        )->registerHandleSaveValueFunc(
//            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
//        )->setCustomAttribute(
//            ["desc", "请勿自拍，上传手持证件照，他人拍摄、双手持证、面容&证件清晰"]
//        )->setRelations(
//            [
//                $this->collectionEqBankCard->getInputName(),
//                WorkOrderApplyContentModel::COLLECTION_EQ_BANK_CARD_NO
//            ]
//        )->setExampleFiles(
//            ["https://file.51kuafu.com/e7/63/2b04f56b4b9cbe5e4dfaf78658fd91388d9a2d9f1bb8180ff9aa437e8318.xlsx"]
//        )->setValue($formContent, "");
//

        KfCashRegisterFormAttribute::getInstance(
            "bankCardImgFront",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "银行卡号面",
            true
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setRemark(
            "请上传银行卡号面"
        )->setExampleImages(
            ['https://file.51kuafu.com/89/b5/a09ed9e9b91ff5fa1ecee2906d6ed74b3c795bdaa6084e416aae72075ef3.png']
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]]
            )
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setRelations(
            [
                $this->collectionType->getInputName(),
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE
            ]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "bankCardImgBack",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "银行卡签名面",
            true
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setRemark(
            "请上传持卡人签名面"
        )->setExampleImages(
            ['https://file.51kuafu.com/18/41/7edcef0d0c9d510ceaa4e6888f1dfb12dc18a727baf151ff6bfa9640deec.png']
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE]]
            )
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setRelations(
            [
                $this->collectionType->getInputName(),
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE
            ]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "accountBank",
            AttributeSupport::INPUT_TYPE_STRING,
            "开户银行全称"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 20)
        )->setPlaceholder(
            "请填写开户银行全称"
        )->setValue($formContent, "");


        KfCashRegisterFormAttribute::getInstance(
            "provinceBank",
            AttributeSupport::INPUT_TYPE_STRING,
            "银行所在省市区"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 20, false)
        )->setPlaceholder(
            "请填写银行所在省市区"
        )->setReject()->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "accountBranchBank",
            AttributeSupport::INPUT_TYPE_STRING,
            "开户支行"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 20)
        )->setPlaceholder(
            "请填写开户支行"
        )->setReject()->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "collectionBankAccount",
            AttributeSupport::INPUT_TYPE_STRING,
            "收款账号"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 36)
        )->setPlaceholder(
            "请填写收款账号"
        )->setValue($formContent, "");


        KfCashRegisterFormAttribute::getInstance(
            "bankReserveMobile",
            AttributeSupport::INPUT_TYPE_MOBILE,
            "银行预留手机号"
        )->setValidateRules(
            KfCashRegisterFormValidate::mobileValidate()
        )->setPlaceholder(
            "请填写银行预留手机号"
        )->setValue($formContent, "");
    }


    /**
     * 执照信息
     *
     * @param Collection $formContent
     */
    public function licenseInformation(Collection $formContent)
    {
        //对私选填
        KfCashRegisterFormAttribute::getInstance(
            "businessLicenseImg",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "营业执照照片",
            true
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate(false)
        )->setExampleImages(
            ["https://file.51kuafu.com/03/6c/7afb9bc267275a8448c285587d8cba592c793150406e75e1c2b9cda59690.png"]
        )->setValue(
            $formContent, []
        )->setBeforeBuildHandle(
            function (AttributeSupport $attributeSupport) use ($formContent) {
                if ($formContent->get("collectionType") == WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC) {
                    $attributeSupport->setValidateRules(
                        KfCashRegisterFormValidate::imgGroupValidate(true)
                    );
                }
            }
        );


        KfCashRegisterFormAttribute::getInstance(
            "enterpriseName",
            AttributeSupport::INPUT_TYPE_STRING,
            "企业名称"
        )->setRelations(
            [
                $this->collectionType->getInputName(),
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE
            ]
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 72, false)
        )->setPlaceholder(
            "请填写企业名称"
        )->setValue(
            $formContent, ""
        )->setBeforeBuildHandle(
            function (AttributeSupport $attributeSupport) use ($formContent) {
                if ($formContent->get("collectionType") == WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC) {
                    $attributeSupport->setValidateRules(
                        KfCashRegisterFormValidate::stringValidate(0, 72, true)
                    );
                }
            }
        );

        KfCashRegisterFormAttribute::getInstance(
            "businessLicenseNumber",
            AttributeSupport::INPUT_TYPE_STRING,
            "营业执照信用代码"
        )->setRelations(
            [
                $this->collectionType->getInputName(),
                WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE
            ]
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 36, false)
        )->setPlaceholder(
            "请输入"
        )->setValue(
            $formContent, ""
        )->setBeforeBuildHandle(
            function (AttributeSupport $attributeSupport) use ($formContent) {
                if ($formContent->get("collectionType") == WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC) {
                    $attributeSupport->setValidateRules(
                        KfCashRegisterFormValidate::stringValidate(0, 36, true)
                    );
                }
            }
        );

        KfCashRegisterFormAttribute::getInstance(
            "businessPremises",
            AttributeSupport::INPUT_TYPE_STRING,
            "经营场所/地址"
        )->setValidateRules(
            KfCashRegisterFormValidate::getInstance()->setRequired(true)
                                      ->setDataType(ValidateSupport::DATA_TYPE_STRING)
                                      ->setContentLength(0, 120)
        )->setPlaceholder(
            "请填写证件上所示的经营地址"
        )->setValue($formContent, "");


        KfCashRegisterFormAttribute::getInstance(
            "legalPersonIdentityCardFront",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "法人身份证人像面",
            true
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
            )
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]
        )->setExampleImages(
            ["https://file.51kuafu.com/64/a4/613f464330f89f1fe43b35ba667b023178af84b4c7ef4574ed0e01c867a5.png"]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "legalPersonIdentityCardBack",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "法人身份证国徽面",
            true
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
            )
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]
        )->setExampleImages(
            ["https://file.51kuafu.com/49/49/784be96a9a10a712d946f3f184b263e074aeb9cea3ed6c7b125f4ed2dd9b.png"]
        )->setValue($formContent, "");


        KfCashRegisterFormAttribute::getInstance(
            "legalPersonIdentityCardValidityPeriod",
            AttributeSupport::INPUT_TYPE_STRING,
            "法人身份证有效期"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 36, false)->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
            )
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]
        )->setValue($formContent, "");


        KfCashRegisterFormAttribute::getInstance(
            "legalPersonIdentityCardWithFront",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "法人手持身份证人像面",
            true
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
            )
        )->setCustomAttribute(
            ["descList", WorkOrderApplyContentModel::DEFAULT_PERSON_IDENTITY_CARD_DESC_LIST]
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]
        )->setExampleImages(
            [WorkOrderApplyContentModel::DEFAULT_PERSON_IDENTITY_CARD_HAND_IMG]
        )->setValue($formContent, []);

        KfCashRegisterFormAttribute::getInstance(
            "legalPersonIdentityCardWithBack",
            AttributeSupport::INPUT_TYPE_IMG_GROUP,
            "法人手持身份证国徽面",
            true
        )->setCustomAttribute(
            ["download", true],
            ["check", true]
        )->registerHandleSaveValueFunc(
            KfCashRegisterFormAttribute::getImgGroupSaveFunc()
        )->setValidateRules(
            KfCashRegisterFormValidate::imgGroupValidate()->setExcludeEq(
                [[$this->collectionType->getInputName()=>
                WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
            )
        )->setCustomAttribute(
            ["descList", WorkOrderApplyContentModel::DEFAULT_PERSON_IDENTITY_CARD_DESC_LIST]
        )->setRelations(
            [$this->collectionType->getInputName(), WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]
        )->setExampleImages(
            [WorkOrderApplyContentModel::DEFAULT_PERSON_IDENTITY_CARD_HAND_BACK_IMG]
        )->setValue($formContent, []);


        KfCashRegisterFormAttribute::getInstance(
            "legalPersonUsername",
            AttributeSupport::INPUT_TYPE_STRING,
            "法人姓名"
        )->setValidateRules(
            (function () use ($formContent) {
                switch ($formContent->get("collectionType")) {
                    case WorkOrderApplyContentModel::COLLECTION_TYPE_PRIVATE:
                        return KfCashRegisterFormValidate::stringValidate(0, 12, false)->setExcludeEq(
                            [[$this->collectionType->getInputName()=>
                            WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
                        );
                        break;
                    case WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC:
                        return KfCashRegisterFormValidate::stringValidate(0, 12, true)->setExcludeEq(
                            [[$this->collectionType->getInputName()=>
                            WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
                        );
                        break;
                    default:
                        return KfCashRegisterFormValidate::stringValidate(0, 12, true);
                        break;
                }
            })()
        )->setPlaceholder(
            "请填写法人姓名"
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "legalPersonIdentityCardNumber",
            AttributeSupport::INPUT_TYPE_STRING,
            "法人身份证号"
        )->setValidateRules(
            KfCashRegisterFormValidate::identityCardValidate()
                                      ->setExcludeEq(
                                          [[$this->collectionType->getInputName()=>
                                          WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC]]
                                      )
        )->setPlaceholder(
            "请填写法人身份证号"
        )->setRelations(
            [
                $this->collectionType->getInputName(),
                WorkOrderApplyContentModel::COLLECTION_TYPE_PUBLIC
            ]
        )->setValue($formContent, "");
    }

    /**
     * 收货信息
     */
    public function takeDeliveryForm(Collection $formContent)
    {
        KfCashRegisterFormAttribute::getInstance(
            "takeDeliveryDetailAddress",
            AttributeSupport::INPUT_TYPE_STRING,
            "收货地址"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 255)
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "takeDeliveryUserName",
            AttributeSupport::INPUT_TYPE_STRING,
            "收件人"
        )->setValidateRules(
            KfCashRegisterFormValidate::stringValidate(0, 36)
        )->setCustomAttribute(
            ["placeholder", "请填写收件人"]
        )->setValue($formContent, "");

        KfCashRegisterFormAttribute::getInstance(
            "takeDeliveryUserMobile",
            AttributeSupport::INPUT_TYPE_MOBILE,
            "收件人手机号"
        )->setValidateRules(
            KfCashRegisterFormValidate::mobileValidate()
        )->setCustomAttribute(
            ["placeholder", "请填写收件人手机号"]
        )->setValue($formContent, "");

    }

    /**
     * 期望开通时间
     */
    public function expectOpenTimeForm(Collection $formContent)
    {
        KfCashRegisterFormAttribute::getInstance(
            "expectOpenTime",
            AttributeSupport::INPUT_DATE,
            "期望开通时间"
        )->setValidateRules(
            KfCashRegisterFormValidate::dateValidate(FormValidate::DATE_VALIDATE_FORMAT_1)
        )->setDateFormat(
            AttributeSupport::DATE_FORMAT_1
        )->setValue($formContent, "");
    }


    /**
     * @param Collection $formContent
     * @return $this
     */
    public function renderForm(Collection $formContent): KfCashRegisterForm
    {
        //门店信息
        $this->shopInfoForm($formContent);
        //收款人信息
        $this->collectionInformationForm($formContent);
        //执照信息
        $this->licenseInformation($formContent);
        //收货人信息
//        $this->takeDeliveryForm($formContent);
        //期望开店时间
        $this->expectOpenTimeForm($formContent);
        return $this;
    }


    /**
     * @return array[]
     * workOrderNo
     */
    public function getFormContent(): array
    {

        return [
            [
                "title"      => "门店信息",
                "attributes" => collect([
                    $this->shopCode,
                    $this->shopName,
                    $this->address,
                    $this->detailAddress,
                    $this->cashierSystem,
                    $this->businessTime,
                    $this->mobile,
                    $this->shopCharge,
                    $this->authorizationLetterImg,

                ])->map(function (KfCashRegisterFormAttribute $attribute) {
                    return $attribute->build();
                })->values()->toArray(),
            ],
            [
                "title"      => "收款信息",
                "attributes" => collect([
                    $this->collectionType,
                    $this->accountOpenPermitImg,
                    $this->bankReceiptImg,


                    $this->collectionPersonIdentityCardFront,
                    $this->collectionPersonIdentityCardBack,
                    $this->collectionPersonIdentityCardValidityPeriod,
                    $this->collectionPersonIdentityCardWithFront,
                    $this->collectionPersonIdentityCardWithBack,

                    $this->collectionPersonUsername,
                    $this->collectionPersonIdentityCardNumber,
                    //$this->collectionEqBankCard,
                    //$this->relationshipProofImg,

                    $this->bankCardImgFront,
                    $this->bankCardImgBack,
                    $this->accountBank,
                    $this->provinceBank,
                    $this->accountBranchBank,
                    $this->collectionBankAccount,
                    $this->bankReserveMobile,
                ])->map(function (KfCashRegisterFormAttribute $attribute) {
                    return $attribute->build();
                })->values()->toArray(),
            ],
            [
                "title"      => "执照信息",
                "attributes" => collect([
                    $this->businessLicenseImg,
                    $this->enterpriseName,
                    $this->businessLicenseNumber,
                    $this->businessPremises,
                    $this->legalPersonIdentityCardFront,
                    $this->legalPersonIdentityCardBack,
                    $this->legalPersonIdentityCardValidityPeriod,
                    $this->legalPersonIdentityCardWithFront,
                    $this->legalPersonIdentityCardWithBack,
                    $this->legalPersonUsername,
                    $this->legalPersonIdentityCardNumber,
                ])->map(function (KfCashRegisterFormAttribute $attribute) {
                    return $attribute->build();
                })->values()->toArray(),
            ],
//            [
//                "title"      => "收货信息",
//                "desc"       => "商米收银机 1 台、扫码盒 1 台、热敏打印机 1 台、钱箱 1 台。",
//                "attributes" => collect([
//                    $this->takeDeliveryDetailAddress,
//                    $this->takeDeliveryUserName,
//                    $this->takeDeliveryUserMobile,
//                ])->map(function (KfCashRegisterFormAttribute $attribute) {
//                    return $attribute->build();
//                })->values()->toArray(),
//            ],
            [
                "title"      => "期望开通时间",
                "attributes" => collect([
                    $this->expectOpenTime,
                ])->map(function (KfCashRegisterFormAttribute $attribute) {
                    return $attribute->build();
                })->values()->toArray(),
            ],
        ];
    }


//    /**
//     * @param string $field
//     * @param $value
//     * @param array $extraParams
//     * @return mixed
//     */
//    public function validate(string $field, $value, array $extraParams = [])
//    {
//        // TODO: Implement save() method.
//        CustomerValidator::extend(
//            'exclude_eq',
//            function ($attribute, $value, $parameters, Validator $validator) {
//                $validator->requireParameterCount(2, $parameters, 'eq');
//                $eqFieldName   = $parameters[0];
//                $eqFieldValue  = $parameters[1];
//                $nowFieldValue = $validator->getData()["$eqFieldName"];
//
//                return $eqFieldValue == $nowFieldValue;
//            }, "当前状态暂不支持修改 【:attribute】 字段");
//
//        return parent::validate($field, $value, $extraParams);
//    }

    /**
     * @param $name
     * @return AttributeSupport
     */
    public function __get($name)
    {
        // TODO: Change the autogenerated stub
        return $this->getAttributeMap()->{$name};
    }

    /**
     * @return AttributeMapSupport
     */
    public function getAttributeMap(): AttributeMapSupport
    {
        // TODO: Implement getAttributeValidateClassName() method.
        return KfCashRegisterFormAttribute::$attributesMap;
    }
}
